package cc.atliberty.structural.composite.ex1;

import java.io.File;

/**
 * @Author 元宵
 * @url www.atliberty.cc
 * @Date 2023-10-31 08:18
 * @description:
 */
public class Client {
    public static void main(String[] args) {
        DirectoryNode directoryNode = new DirectoryNode("E:\\python_code");
        createTree(directoryNode);
        directoryNode.display();
    }

    private static void createTree(DirectoryNode directoryNode) {
        File file = new File(directoryNode.nodeName);
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                FileLeaf fileLeaf = new FileLeaf(files[i].getAbsolutePath());
                directoryNode.addLeaf(fileLeaf);
            }
            if (files[i].isDirectory()) {
                DirectoryNode directoryNode1 = new DirectoryNode(files[i].getAbsolutePath());
                directoryNode.addNode(directoryNode1);
                createTree(directoryNode1);
            }
        }
    }


}
